package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.TestSummaryDao;
import com.exigen.perflabstat.models.TestSummary;


public class TestSummaryJpaDao extends GenericJPADAO<TestSummary, Long> implements TestSummaryDao  {
	
	public TestSummaryJpaDao() {
		super(TestSummary.class);
	}

	@SuppressWarnings("unchecked")
	public List<TestSummary> allTestSummarys() {
		
		Query query = getEntityManager().createQuery("from TestSummary");
		
		List<TestSummary> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TestSummary checkIfExists(TestSummary testSummary) {
		
		TestSummary test;
		
		Query query = getEntityManager().createQuery("select ts from TestSummary ts where ts.SCENARIO_ID = :scenarioId and ts.SCENARIO_TYPE_ID = :scenarioTypeId and ts.STATE = :state");
		query.setParameter("scenarioId", testSummary.getSCENARIO_ID());
		query.setParameter("scenarioTypeId", testSummary.getSCENARIO_TYPE_ID());
		query.setParameter("state", testSummary.getSTATE());
		query.setMaxResults(1);
		
		List<TestSummary> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		test = result.get(0);
		
		return test;
	}

}